Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

71
Visualizações
Discord.js "voiceStateUpdate" called twice

I am trying to create a temporary channel what is working with "Slash" commands. I am almost there but I am getting an error when creating a second channel because the "voiceStateUpdate" is getting called twice.

else if (commandName === "createchannel") {
   var channelName = options.getString("channelname");
   var rolesThatCanJoin = options.getRole("roles");
   var state = options.getString("state");
   var channel = interection.guild.channels.create(channelName, {
        type: "GUILD_VOICE"
        }).then((channel) => { 
        channel.setParent("670691620844470320")
        createdChannelID = channel.id;

        interection.reply({
          content: `**Channel named:** ${channelName}\n**Role that can join:** ${rolesThatCanJoin}\n**State:** ${state}`,
                ephemeral: true,
                })

        client.on('voiceStateUpdate', (oldState, newState) => {
            var newChannelID = newState.channelId;
                
            if (newChannelID === createdChannelID) {
              console.log("User has joined voice channel with id " + newChannelID);
            } 
            else {
               console.log("User has left");
               channel.delete()
            }
         });
      });
    }

Console:

User has joined voice channel with id 936252040865284156
User has left
User has joined voice channel with id 936252068568641576
User has joined voice channel with id 936252068568641576
User has left
User has left

Error:
DiscordAPIError: Unknown Channel
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It seems like every time the command runs, you are calling client.on('voiceStateUpdate'... again, which adds another listener. This is causing you to receive the same event multiple times. I suggest you move your client.on('voiceStateUpdate'... code to another location where it will get called once, same as how you are handling other events like client.on('messageCreate'... or client.on('interactionCreate'...

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda